/*
 * PVPRewardResource.h
 *
 *  Created on: 2013. 9. 13.
 *      Author: mega@gamevil.com
 */

#ifndef PVPREWARDRESOURCE_H_
#define PVPREWARDRESOURCE_H_

#include <map>

namespace ProjectZ { namespace NResource {

class PVPRewardData
{
public:
	struct Key
	{
		Key() : type(0), sub_type(0) {}
		Key(int rType, int rSubType) : type(rType), sub_type(rSubType) {}

		int type;
		int sub_type;

		bool operator == (const Key & rSide) const
		{
			if (this->type == rSide.type && this->sub_type == rSide.sub_type)
				return true;

			return false;
		}

		bool operator < (const Key & rSide) const
		{
			if (this->type < rSide.type)
			{
				return true;
			}
			else if (this->type == rSide.type)
			{
				if (this->sub_type < rSide.sub_type)
					return true;
			}

			return false;
		}
	};

public:
	struct FlyweightRate
	{
		int _TYPE;
		int _SUB_TYPE;
		int _VALUE1;
		int _VALUE2;
	};

	struct FlyweightItem
	{
		int _MIN_LEVEL;
		int _MAX_LEVEL;
		int _WEAPONE;
		int _HELMET;
		int _ARMOR;
		int _GLOVES;
		int _SHOES;
		int _NECKLACE;
		int _CLOAK;
		int _RING;
		int _CHARM;
	};

public:
	typedef std::map<Key, FlyweightRate *> PVPREWARDRATETREE;
	typedef std::map<int, FlyweightItem *> PVPREWARDITEMTREE;

public:
	PVPRewardData() {}
	virtual ~PVPRewardData();

	bool LoadResource(int company, int saleCode);

	FlyweightRate * GetFly(Key & clsKey);
	FlyweightItem * GetFly(int level);

	PVPREWARDRATETREE & GetRateTree() { return clsFlyRateTree; }
	PVPREWARDITEMTREE & GetItemTree() { return clsFlyItemTree; }

private:
	void	ClearRateTree();
	void	ClearItemTree();

private:
	PVPREWARDRATETREE clsFlyRateTree;
	PVPREWARDITEMTREE clsFlyItemTree;
};





class PVPRewardResource
{
public:
	PVPRewardResource();
	virtual ~PVPRewardResource();

	bool LoadResource();

	PVPRewardData::FlyweightRate * GetFly(int company, int saleCode, PVPRewardData::Key & clsKey);
	PVPRewardData::FlyweightItem * GetFly(int company, int saleCode, int level);

	void PVPReward(User * pUser, NLogic::Item::Data & clsData);

private:
	PVPRewardData::FlyweightRate * GetFlyFromType(PVPRewardData::PVPREWARDRATETREE & clsRateTree, int type);
	int GetClassType();
	int GetItemTid(PVPRewardData * pPVPReward, int level, int sheet);
	int GetItemSheet(int minType, int maxType);
	int GetEtcItemTid(PVPRewardData * pPVPReward);
	int GetItemLevelDown(PVPRewardData * pPVPReward, int level);
	int AddEffect(PVPRewardData * pPVPReward, int effectValue);


private:
	PVPRewardData * pPVPRewardAD;
	PVPRewardData * pPVPRewardIOS;
};

} /* NResource */ } /* ProjectZ */


#endif /* PVPREWARDRESOURCE_H_ */
